package com.example.a7822.myapplication;

import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;

import com.example.a7822.myapplication.shopcart.SPCartManager;
import com.example.a7822.myapplication.shopcart.beans.GoodBean;
import com.example.a7822.myapplication.shopcart.view.CartAdapter;

import org.linphone.CallActivity;
import org.linphone.LinphoneManager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.example.a7822.myapplication.Constant.TAG;

/**
 * Created by flyln on 2017/10/26 21:30.
 * email:xyf_uestc@163.com
 */

public class YTCartActivity extends CallActivity {

    @BindView(R.id.rv_cart) RecyclerView mRecyclerView;
    @BindView(R.id.incall_stats) View cartView;
//    @BindView(R.id.tv_hello) TextView tv_hello;
    private LinearLayoutManager mLayoutManager;
    private CartAdapter mAdapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        LayoutInflater.from(this).inflate(R.layout.activity_cart, sideMenu);

//        View superView = super.findViewById(android.R.id.content);
//        ViewGroup root = (ViewGroup) superView.getParent();
//
        LayoutInflater inflater = LayoutInflater.from(this);
        View v = inflater.inflate(R.layout.incall_cart, null, false);
        cartView = v;

        status.initCallStatsRefresher(LinphoneManager.getLc().getCurrentCall(),cartView);

//        View child = getLayoutInflater().inflate(R.layout.activity_cart, null);
////        View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.activity_cart, null,false);
//        ViewGroup.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
//        addContentView(child,params);

        ButterKnife.bind(this);

        mRecyclerView.setHasFixedSize(true);

        mLayoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(mLayoutManager);

        mRecyclerView.setItemAnimator(new DefaultItemAnimator());


        List<GoodBean> goodList = new ArrayList<>();
        for (int i=0 ; i < 6 ; i++){
            GoodBean goodBean = new GoodBean();
            goodBean.setGoodName(i+"苹果"+i);
            goodBean.setGoodPic("http://120.26.39.36/uploads/shop/26/logo.jpg");
            goodBean.setGoodPriceNow(i+1);
            goodBean.setGoodAmount(1);
            goodList.add(goodBean);
        }

        SPCartManager.getInstance().setGoodList(goodList);
        mAdapter = new CartAdapter(this,SPCartManager.getInstance().getGoodList());
//        mAdapter.setOnItemClickListener(mOnItemClickListener);
        mRecyclerView.setAdapter(mAdapter);

        mRecyclerView.setOnTouchListener(//静止下拉刷新时，向上滑动操作,recycle自带bug
                new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
//                        if (mIsRefreshing) {
//                            return true;
//                        } else {
//                            return false;
//                        }
                        return false;
                    }
                }
        );
        Log.d(TAG,"YTCartActivity:onCreate");


//        tv_hello.setText("你好毒");


//        rvCart.setHasFixedSize(true);
//
//        mLayoutManager = new LinearLayoutManager(this);
//        rvCart.setLayoutManager(mLayoutManager);
//
//        rvCart.setItemAnimator(new DefaultItemAnimator());
//        mAdapter = new NewsAdapter(getActivity().getApplicationContext());
//        mAdapter.setOnItemClickListener(mOnItemClickListener);
//        rvCart.setAdapter(mAdapter);
//        rvCart.addOnScrollListener(mOnScrollListener);



    }

}
